﻿@model Project3.Models.PhotoCollectionAndId

@{
    ViewBag.Title = "MeetingPhoto";
}

<h2>Photos from @Html.DisplayFor(model => Model.meeting.EventName) Meeting</h2>

@{
    var collection = Model.collection;
}

@if (collection.Count == 0){<p>Sorry, there are no photos from this meeting.</p>}

@{var rowNum = 3;}

<table>
    @for(var i = 0; i < (collection.Count/rowNum); i++)
    {
        <tr>
        @for (var j = 0; j < rowNum; j++)
        {
            var photo = collection[i * 3 + j];
                                                               
            <td>
                @Html.ActionLink(photo.Title, "IndividualPhoto", "Photo", new { id = Model.id,photoID = photo.PhotoId },null)
                <img style="display: block;" src ='@Url.Content(photo.SmallUrl)' alt =""/>
            </td>          
        }
        </tr>
    }

    @if ((collection.Count % rowNum) != 0)
    {
        // Handeling the last partial row if need be
        <tr>
            @for (var j = collection.Count - (collection.Count % rowNum); j < collection.Count; j++ )
            {
                var photo = collection[j];
                                                               
                <td>
                    @Html.DisplayFor(model => photo.Title)
                    <img style="display: block;" src ='@Url.Content(photo.SmallUrl)' alt =""/>
                </td>  
            }
        </tr>
    }
</table>

<p>
    @Html.ActionLink("Back to Gallery", "Index")
    @Html.ActionLink("Prev",
            "MeetingPhoto",
            "Photo",
            new {id = Model.id , page = collection.Page - 1 },
            null)
    @Html.ActionLink("Next",
            "MeetingPhoto",
            "Photo",
            new {id = Model.id , page = collection.Page + 1 },
            null)
</p>
